import Vue from 'vue'
import Router from 'vue-router'
import {
  NS
} from '../facility/constant.js'
import beforeEach from './beforeEach.js'
import Home from '@/components/home/Index'
import IndexHome from '@/components/home/home'
import HotDownload from '@/components/home/HotDownload'
import NewestUpload from '@/components/home/NewestUpload'
import Personal from '@/components/personal'
import PersonalHome from '@/components/personal/Home'
import Download from '@/components/personal/Download'
import Message from '@/components/personal/Message'
import Apply from '@/components/personal/Apply'
import AdminHome from '@/components/Admin/home/Index'
Vue.use(Router)


const NS_HOME = NS.HOME
const NS_PERSONAL = NS.PERSONAL
let isAdmin = true
let router = new Router({
  routes: [{
    path: '/',
    component: Home,
    children: [{
      path: '',
      component: IndexHome,
      children: [{
        path: '',
        name: NS_HOME,
        components: {
          'hot-download': HotDownload,
          'newest-upload': NewestUpload
        }
      }]
    },
    {
      path: 'hot-download',
      component: HotDownload
    },
    {
      path: 'newest-upload',
      component: NewestUpload
    }
    ]
  },

  {
    path: '/personal',
    component: Personal,
    children: [{
      path: '',
      component: PersonalHome,
      children: [{
        path: '',
        name: NS_PERSONAL,
        components: {
          download: Download,
          message: Message,
          apply: Apply
        }
      }]
    },
    {
      path: 'download',
      component: Download,
      meta: 'download'
    },
    {
      path: 'message',
      component: Message,
      meta: 'message'
    },
    {
      path: 'apply',
      component: Apply,
      meta: 'apply'
    }
    ]
  },
  {
    path: '/admin',
    name: 'adminCenter', 
    meta: {title: '后台管理中心'},
    component: AdminHome,
    children: [
      {
        name: 'login',
        path: '/admin/login',
        meta: { title: '用户登录' }
      }
    ]
  }
  ]
})
beforeEach(router)
export default router
